<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增【请填写功能名称】')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-order-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">订单地址：</label>
                <div class="col-sm-8">
                    <input name="customerOrderAddress" class="form-control" type="text">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">客户：</label>
                <div class="col-sm-8">
                    <select class="form-control" name="customerId" id="sel">
                        <option>--请选择--</option>
                    </select>
                </div>
            </div>


            <!--选择商品-->
            <div class="form-group">
                <label class="col-sm-3 control-label sp"></label>
                <div class="col-sm-8">
                    <span class="form-control">如需多样商品,请多次点选</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label sp">选择商品：</label>
                <div class="col-sm-8">
                    <select class="form-control" id="selpro">
                        <option>--请选择--</option>
                    </select>
                </div>
            </div>
            <!--输入商品数量-->
            <div class="form-group">
                <label class="col-sm-3 control-label">商品数量：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" id="pnum">
                </div>
            </div>


            <div class="form-group">    
                <label class="col-sm-3 control-label">期望到货时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="customerOrderExpectArrivalDatetime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">订单状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <input type="text" name="customerOrderStatus" value="未接单" readonly>
                    </div>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">

        var arr1 = "";
        var arr2 = "";

        var prefix = ctx + "system/order";
        //alert(ctx);
        $("#form-order-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                //name=zs&pwd=p
                $.operate.save(prefix + "/add", $('#form-order-add').serialize()+"&arr1="+arr1+"&arr2="+arr2);
            }
        }

        //查询客户信息
        $(function () {
            $.post("/system/customer/findAllCustomer",function (result) {
                for (var i in result) {
                    $("#sel").append("<option value='"+result[i].customerId+"'>"+result[i].customerName+"</option>")
                }
            })
        });


        //查询商品的信息
        $(function () {
            $.post("/system/product/findAllProduct",function (result) {
                for (var i in result) {
                    $("#selpro").append("<option value='"+result[i].productId+"'>"+result[i].productName+result[i].productPrice+"</option>")
                }
            });

            //得到选中商品的ID
            $("#selpro").change(function () {
                if (arr1!=""){
                    arr1+=",";
                }
                arr1+=$("#selpro").val();
                $("#pnum").val(null);
            });
            //得到选中商品的数量
            $("#pnum").blur(function () {
                if (arr2!=""){
                    arr2+=",";
                }
                arr2+=$("#pnum").val();
            })
        });



        $("input[name='customerOrderStartDatetime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='customerOrderExpectArrivalDatetime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>